import org.tmatesoft.svn.core.*;
import org.tmatesoft.svn.core.internal.wc2.ng.SvnDiffGenerator;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc2.SvnOperationFactory;
import org.tmatesoft.svn.core.wc2.SvnTarget;

import java.io.File;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;

public class SvnDiff {


    public static void main(String[] args) throws SVNException {

        final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
        //final SvnLog log = svnOperationFactory.createLog();

        SVNURL url = SVNURL.parseURIEncoded("http://maven-svn-diff-plugin.googlecode.com/svn/trunk/");

        //log.setSingleTarget(SvnTarget.fromURL(url));

        long startRevision = 5;
        long endRevision = 6;

        //log.addRange(SvnRevisionRange.create(SVNRevision.create(startRevision), SVNRevision.create(endRevision)));
        //log.setDiscoverChangedPaths(true);
        //final SVNLogEntry logEntry = log.run();

        SVNRepository repository = SVNRepositoryFactory.create(url);
        Collection<SVNLogEntry> logEntries = repository.log( new String[] { "" } , null , startRevision , endRevision , true , true );

        listEntries(repository, "/svn-diff");

//        final SvnDiffGenerator diffGenerator = new SvnDiffGenerator();
//        diffGenerator.setBasePath(new File(""));
//
//        // SVNRevision.create(new Date())
//
//
//        final org.tmatesoft.svn.core.wc2.SvnDiff diff = svnOperationFactory.createDiff();
//        diff.setSingleTarget(SvnTarget.fromURL(url));
//        diff.setSource(SvnTarget.fromURL(url), SVNRevision.create(startRevision), SVNRevision.create(endRevision));
//        diff.setDiffGenerator(diffGenerator);
//        diff.setOutput(System.out);
//        diff.run();
    }


    public static void listEntries( SVNRepository repository, String path ) throws SVNException {
          Collection entries = repository.getDir( path, 6 , null , (Collection) null );
          //Collection entries = repository.getDir( path, -1 , null , (Collection) null );
          Iterator iterator = entries.iterator( );
          while ( iterator.hasNext( ) ) {
              SVNDirEntry entry = ( SVNDirEntry ) iterator.next( );
              System.out.println( "/" + (path.equals( "" ) ? "" : path + "/" ) + entry.getName( ) +
                                 " ( author: '" + entry.getAuthor( ) + "'; revision: " + entry.getRevision( ) +
                                 "; date: " + entry.getDate( ) + ")" );
//              System.out.println(entry.getAuthor());
              if ( entry.getKind() == SVNNodeKind.DIR ) {
                  listEntries( repository, ( path.equals( "" ) ) ? entry.getName( ) : path + "/" + entry.getName( ) );
              }
          }
      }
}
